Loading Interactive Course...
Kotlin is a modern, statically-typed programming language that runs on the Java Virtual Machine (JVM). It's concise, safe, and interoperable with Java. Every Kotlin program has a basic structure that the compiler uses to execute code correctly.
fun main() is the entry point of every Kotlin programprintln() prints text to the console with a new lineval declares a read-only (immutable) variable${}// for single-line or /* */ for multi-lineKotlin provides several basic data types and two types of variable declarations: val for immutable (read-only) variables and var for mutable variables. Understanding data types is crucial for writing type-safe Kotlin code.
val for variables that won't change (immutable)var for variables that can change (mutable)Int, Double, Float, Long, Short, Byte, Char, Boolean, String: Type after the variable name$variable or ${expression}Control flow statements allow your program to make decisions and repeat actions. Kotlin provides if-else expressions, when expressions (similar to switch), and various loop constructs like for and while.
if-else is an expression that returns a valuewhen is more powerful than traditional switch statements.. operator (e.g., 1..5)step to skip values in a rangefor loops can iterate over ranges, arrays, collections, etc.while checks condition before executiondo-while executes at least once before checking conditionFunctions are the building blocks of Kotlin programs. They allow you to organize code into reusable units. Kotlin functions can have parameters, return values, default arguments, and can be defined in various ways including as expressions.
fun keyword: Type= instead of a blockUnit (similar to void){}Kotlin is a fully object-oriented language that supports classes, objects, inheritance, interfaces, and other OOP concepts. It improves upon Java's OOP model with features like data classes, sealed classes, and properties.
class keywordval properties are read-only, var properties are mutable: symbol (e.g., class Child : Parent())Kotlin provides a rich set of collection types and powerful functional programming capabilities. Collections can be mutable or immutable, and lambda expressions enable concise and expressive code for processing data.
listOf() creates immutable lists, mutableListOf() creates mutable onesfilter, map, reduce process collections{ parameters -> body } enable concise codeit keyword refers to the single parameter in a lambdaUse this space to experiment with everything you've learned. Try combining different Kotlin concepts and see the results in real-time! This is your sandbox to practice and explore.
Shape with an area() functionCircle and Rectanglearea() function in each subclasswhen expression